package neusoft.example.com.yuejian06.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import neusoft.example.com.yuejian06.Bean.Comment;
import neusoft.example.com.yuejian06.PublicActivity;
import neusoft.example.com.yuejian06.R;

public class PictureCommentListAdapter  extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private LayoutInflater inflater;
    private List<Comment> list;
    private Context context;
    private PublicActivity publicActivity;

    public PictureCommentListAdapter(Context context){
        this.inflater = LayoutInflater.from(context);
        this.context=context;
    }
    public PictureCommentListAdapter(Context context, List<Comment> list) {
        this.context = context;
        this.list = list;
    }
    public void setList(List<Comment> list){
        this.list = list;
        notifyDataSetChanged();
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView=LayoutInflater.from(context).inflate(R.layout.adapter_picturecomment, parent, false);
        ViewHolder viewHolder = new ViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        publicActivity=new PublicActivity();
        Comment bean = list.get(position);
        if(bean == null) return;
        final PictureCommentListAdapter.ViewHolder viewHolder = (ViewHolder) holder;

        viewHolder.user_name.setText(bean.getUser_name());
        viewHolder.comment_content.setText(bean.getComment_content());
        viewHolder.comment_time.setText(bean.getComment_time());

        Picasso.with(context)
                .load(publicActivity.getIp()+"static/user_picture/"+bean.getUser_pic())
                .into(viewHolder.user_pic);
    }
    @Override
    public int getItemCount() {
        if(list == null)
            return 0;
        else
            return list.size();
    }
    public static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView user_pic;
        TextView user_name;
        TextView comment_content;
        TextView comment_time;

        public ViewHolder(View itemView) {
            super(itemView);
            user_pic = (ImageView) itemView.findViewById(R.id.user_pic);
            user_name = (TextView) itemView.findViewById(R.id.user_name);
            comment_content = (TextView) itemView.findViewById(R.id.comment_content);
            comment_time = (TextView) itemView.findViewById(R.id.comment_time);
        }
    }
}
